package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import com.px.user.model.PagingModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.math.BigDecimal;
import java.sql.Timestamp;

@Data
@SuperBuilder
@NoArgsConstructor
@Entity(name = "red_pack")
@EqualsAndHashCode(callSuper = true)
@org.hibernate.annotations.Table(appliesTo = "red_pack", comment = "红包表")
public class RedPack extends PagingModel {

    @Id
    @ApiModelProperty(value = "主键", hidden = true)
    @NotNull(groups = {ActionModel.Update.class})
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @Column(columnDefinition = "bigint comment '创建人ID'")
    @ApiModelProperty(value = "创建人ID", example = "1", hidden = true)
    private Long creatorId;

    @ApiModelProperty(value = "房间ID", example = "3")
    @NotNull(groups = {ActionModel.Insert.class})
    @Column(columnDefinition = "bigint comment '房间ID'")
    private Long roomId;

    @ApiModelProperty(value = "金额", example = "9.9")
    @NotNull(groups = {ActionModel.Insert.class})
    @Column(columnDefinition = "decimal(12,2) comment '金额'")
    private BigDecimal money;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "数量", example = "9")
    @Column(columnDefinition = "int comment '数量'")
    private Integer amount;

    @ApiModelProperty(value = "红包分类：one#定向红包,random#随机红包", example = "@不提交")
    @Column(columnDefinition = "varchar(16) comment '红包分类：one#定向红包,random#随机红包'")
    private String category;

    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    @Generated(GenerationTime.INSERT)
    private Timestamp createTime;

    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    @Generated(GenerationTime.INSERT)
    private Timestamp updateTime;

    /**
     * 扩展字段
     */
    @Transient
    @ApiModelProperty(value = "昵称", example = "@不提交")
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private String nickname;
}
